package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONObject;

/**
 * Created by Administrator on 2016/6/23.
 */
@HttpInlet(Conn.INLET_API_INSURANCE_TORENEW)
public class PostApiTorenewBusiness extends BaseAsyPost<PostApiTorenewBusiness.Info> {
    public String type, userid, policyid, test;

    public PostApiTorenewBusiness(AsyCallBack<PostApiTorenewBusiness.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");

        if (jsonObject.optInt("code") == 200) {

            Info info = new Info();

            JSONObject data = jsonObject.optJSONObject("data");

            info.ordersn = data.optString("ordersn");
            info.applicant = data.optString("applicant");
            info.insurance_id = data.optString("insurance_id");
            info.stores_id = data.optString("stores_id");
            info.covered_area = data.optString("covered_area");
            info.policy_type = data.optString("policy_type");
            info.email = data.optString("email");
            info.dispatching = data.optString("dispatching");
            info.manager_code = data.optString("manager_code");

            //被保人信息
            Insurant_info insurantInfo = new Insurant_info();

            JSONObject infoObject = data.optJSONObject("insurant_info");

            insurantInfo.name = infoObject.optString("name");
            insurantInfo.id_number = infoObject.optString("id_number");
            insurantInfo.tel = infoObject.optString("tel");
            insurantInfo.address = infoObject.optString("address");
            insurantInfo.id_url = infoObject.optString("id_url");

            info.insurant_info = insurantInfo;

            //车信息
            Vehicle_info vehicleInfo = new Vehicle_info();

            JSONObject vehicleObject = data.optJSONObject("vehicle_info");

            vehicleInfo.brand_model = vehicleObject.optString("brand_model");
            vehicleInfo.plate_num = vehicleObject.optString("plate_num");
            vehicleInfo.vin_code = vehicleObject.optString("vin_code");
            vehicleInfo.engine_num = vehicleObject.optString("engine_num");
            vehicleInfo.use_nature = vehicleObject.optString("use_nature");
            vehicleInfo.vehicle_type = vehicleObject.optString("vehicle_type");
            vehicleInfo.regtime = vehicleObject.optString("regtime");
            vehicleInfo.passengers = vehicleObject.optString("passengers");
            vehicleInfo.weight = vehicleObject.optString("weight");
            vehicleInfo.driving_area = vehicleObject.optString("driving_area");
            vehicleInfo.vehicle_origin = vehicleObject.optString("vehicle_origin");
            vehicleInfo.drive_url = vehicleObject.optString("drive_url");
            vehicleInfo.people_car_url = vehicleObject.optString("people_car_url");

            info.vehicle_info = vehicleInfo;

            //公司信息
            JSONObject companyObject = data.optJSONObject("company");

            Company company = new Company();

            company.id = companyObject.optString("id");
            company.title = companyObject.optString("title");
            company.picurl = Conn.PIC + companyObject.optString("picurl");
            company.privilege = companyObject.optString("privilege");

            info.company = company;

            return info;
        }

        return null;
    }


    public static class Info {

        public String ordersn, applicant;
        public String insurance_id, stores_id, covered_area;//投保公司id ，门店id，地区id
        public String policy_type, email, dispatching, manager_code;// 保单类型， 邮箱， 配送地址

        public Insurant_info insurant_info;

        public Vehicle_info vehicle_info;

        public Company company;

    }

    public static class Insurant_info {

        public String name, id_number, tel, address, id_url;

//        "name": "沈玉鑫",
//                "id_number": "230183199205103215",
//                "tel": "18944610773",
//                "address": "黑龙江省尚志市马延乡红房子村132号",
//                "id_url": ""
    }

    public static class Vehicle_info {

        public String brand_model, plate_num, vin_code, engine_num, use_nature, vehicle_type, regtime, passengers, weight, driving_area, vehicle_origin, drive_url, people_car_url;

//        "brand_model": "长安牌SC7106觯B",
//                "plate_num": "黑A628UF",
//                "vin_code": "LS5A3BBD5BA551400",
//                "engine_num": "B65J0568751",
//                "use_nature": "2",
//                "vehicle_type": "1",
//                "regtime": "2011-09-21",
//                "passengers": "15",
//                "weight": "",
//                "driving_area": "大东北",
//                "vehicle_origin": "国产",
//                "drive_url": "",
//                "people_car_url": ""

    }

    public static class Company {

        public String id, title, picurl, privilege;
//                 "id": "2",
//                "title": "人保车险",
//                "picurl": "/Public/uploads/20161226/5860e1561f9bd.png",
//                "privilege": "赠品XXXXXXXX"

    }


}
